package com.example.demopage.mybatis;

import com.alibaba.fastjson.JSON;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.util.Properties;

@Intercepts({@Signature(
        type = Executor.class,
        method = "prepare",
        args = {MappedStatement.class, Object.class})})
public class TableNamePlugin implements Interceptor {

    public TableNamePlugin() {
        System.out.println("TableNamePlugin初始化...");
    }

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println(invocation.getMethod().getName());
        System.out.println(JSON.toJSONString(invocation.getArgs()));
        System.out.println(invocation.getTarget());
        return null;
    }

    @Override
    public Object plugin(Object o) {
        return null;
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
